import download from 'download-git-repo'
import ora from 'ora'
import chalk from 'chalk'
import figlet from 'figlet'
const clone = function(repo, dest, options, callback){
  console.log(chalk.blue("正在拉取项目....."))
  const spinner = ora('Loading unicorns').start();

  setTimeout(() => {
    spinner.color = 'yellow';
    spinner.text = 'Loading rainbows';
  }, 1000);
  return new Promise((resolve, reject) => {
    console.log(repo)
    download(repo, dest, options, (err) => {
      if(err) {
        spinner.fail()
        reject(err)
      } else {
        spinner.succeed('拉取成功')
        console.log(chalk.blue("已经结束啦！！！"))

        figlet("GGBoo!!", function (err, data) {
          if (err) {
            console.log("Something went wrong...");
            console.dir(err);
            return;
          }
          console.log(data);
        });
        figlet.text(
          "Boo!",
          {
            font: "Ghost",
            horizontalLayout: "default",
            verticalLayout: "default",
            width: 80,
            whitespaceBreak: true,
          },
          function (err, data) {
            if (err) {
              console.log("Something went wrong...");
              console.dir(err);
              return;
            }
            console.log(data);
          }
        );
        resolve()
      }
    })
  })
}
export default clone;